package ModelLayer;
import java.util.ArrayList;

/**
 * Dvd class er her vi opretter objekterne dvd
 * Den bruges også som vores copies container
 * 
 * @author (Frederik, Simon, Claus, Minh, Nichlas & Nicolai) 
 * @version (a version number or a date)
 */
public class Dvd
{
    // instance variables - replace the example below with your own
    private String barcode;
    private String title;
    private String artist;
    private String publicationDate;

    private ArrayList<Copy> copies;

    /**

     * Constructor for objects of class Person
     */
    public Dvd(String barcode, String title, String artist, String publicationDate)
    {
        // initialise instance variables
        this.barcode = barcode;
        this.title = title;
        this.artist = artist;
        this.publicationDate = publicationDate;

        copies = new ArrayList<Copy>();
    }

    //Setters
    public void setBarcode(String barcode)
    {
        this.barcode = barcode;
    }

    public String getBarcode()
    {
        return barcode;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getTitle()
    {
        return title;
    }

    public void setArtist(String artist)
    {
        this.artist = artist;
    }

    public String getArtist()
    {
        return artist;
    }

    public void setPublicationDate(String publicationDate)
    {
        this.publicationDate = publicationDate;
    }

    public String getPublicationDate()
    {
        return publicationDate;
    }

    /**
     * en metode til at finde en kopi
     * 
     * start med while (ikke fundet & i er mindre end copies størrelse) 
     * 
     * hvis (serialNumber er lig med (copies <-> serialNumber)
     * ellers incrementeres der med en og søges igen
     * 
     * hvis fundet returneres kopien
     */
    public Copy findCopy(String serialNumber)
    {
        int i=0;
        boolean found = false;
        while (!found && i<copies.size()){

            if (serialNumber.equals (copies.get(i).getSerialNumber())){
                found = true;
            }
            else {
                i++;
            }

            if (found){                
                return copies.get(i);
            }

        }
        return null;
    }

    public void addCopy(Copy copy)
    {
        copies.add(copy);
    }
    
    public void deleteCopy(Copy copy)
    {
        copies.remove(copy);
    }
    
    public int amountOfCopies()
    {
        return copies.size();
    }
    
    public void printInfo()
    {
        System.out.println("***DVD info***");
        System.out.println("Title: " + title);
        System.out.println("Artist: " + artist);
        System.out.println("Publication date: " + publicationDate);
        System.out.println("Barcode: " + barcode);
        System.out.println("Copies: " + amountOfCopies());
        System.out.println("Serial number for each copy");
        for(Copy copy : copies) {
            System.out.println("Serial number: " + copy.getSerialNumber());
        }

    }
}
